
var t = document.querySelector(".t");
console.log(t);
var m = document.querySelectorAll("#navbarSupportedContent .nav-item  a  ");
console.log(m);
window.onscroll =function () {
    var height = document.documentElement.scrollTop || document.body.scrollTop;
    console.log(height)
    if (document.documentElement.scrollTop > 200 || document.body.scrollTop > 200){

        t.style.display="block";
    }else{
        t.style.display="none";
    }
    for(var h = 0; h < m.length; h++) {
        m[h].classList.remove('active');
        if(height >=0 && height <500) {
            m[0].classList.add('active');
        }else if(height >= 500 && height <900) {
            m[1].classList.add('active');
        } else if(height >= 900 && height < 1600) {
            m[2].classList.add('active');
        } else if(height >=1600 && height < 2000) {
            m[3].classList.add('active');
        } else if(height >= 2000&&height<2400) {
            m[4].classList.add('active');
        }else if(height >= 2400&&height<2555){
            m[5].classList.add('active');
        }
    }
};
m[0].addEventListener('click', function() {
    m[0].classList.add('active');
    window.scrollTo({
        top: 0,
        //平滑滚动
        behavior: 'smooth'
    })
})
m[1].addEventListener('click', function() {
    m[1].classList.add('active');
    window.scrollTo({
        top: 500,
        behavior: 'smooth'
    })
})
m[2].addEventListener('click', function() {
    m[2].classList.add('active');
    window.scrollTo({
        top:900,
        behavior: 'smooth'
    })
})
m[3].addEventListener('click', function() {
    m[3].classList.add('active');
    window.scrollTo({
        top: 1600,
        behavior: 'smooth'
    })
})
m[4].addEventListener('click', function() {
    m[4].classList.add('active');
    window.scrollTo({
        top: 2000,
        behavior: 'smooth'
    })
})
m[5].addEventListener('click', function() {
    m[5].classList.add('active');
    window.scrollTo({
        top: 2400,
        behavior: 'smooth'
    })
})

t.addEventListener('click',function () {
//            window.scrollTo(0,0);
    window.scrollTo({
        top:0,
        behavior:'smooth'
    })
})

